feat(apps): emit typed error envelopes across the apps domain#1288
feat(apps): emit typed error envelopes across the apps domain#1288evandance wants to merge 1 commit into
Conversation
|
Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR migrates the ChangesApps Domain Typed Error Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e76456c923dd4c1e82f1370e37d1f3b57da387b5🧩 Skill updatenpx skills add larksuite/cli#feat/errs-migrate-apps -y -g |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1288 +/- ##
=======================================
Coverage 71.58% 71.58%
=======================================
Files 689 690 +1
Lines 65521 65558 +37
=======================================
+ Hits 46901 46932 +31
- Misses 14972 14975 +3
- Partials 3648 3651 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
shortcuts/apps/html_publish_client_test.go (1)
21-31:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd config-dir isolation in the test runtime helper.
newAppsClientRuntimeusescmdutil.TestFactorybut does not isolate config state. This can leak state across tests when config-backed paths are touched.💡 Suggested fix
func newAppsClientRuntime(t *testing.T) (*common.RuntimeContext, *httpmock.Registry) { t.Helper() + t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) cfg := &core.CliConfig{ AppID: "test-app-" + strings.ToLower(t.Name()), AppSecret: "test-secret", Brand: core.BrandFeishu, UserOpenId: "ou_test", }As per coding guidelines:
**/*_test.gomustUse t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) to isolate config state in tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/apps/html_publish_client_test.go` around lines 21 - 31, The test helper newAppsClientRuntime should isolate config state: before calling cmdutil.TestFactory set the environment var LARKSUITE_CLI_CONFIG_DIR to a temp dir via t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()), so tests don't share config-backed paths; update newAppsClientRuntime to call t.Setenv(...) as the first action in the function (reference newAppsClientRuntime and the call site cmdutil.TestFactory).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@shortcuts/apps/html_publish_client_test.go`:
- Around line 21-31: The test helper newAppsClientRuntime should isolate config
state: before calling cmdutil.TestFactory set the environment var
LARKSUITE_CLI_CONFIG_DIR to a temp dir via t.Setenv("LARKSUITE_CLI_CONFIG_DIR",
t.TempDir()), so tests don't share config-backed paths; update
newAppsClientRuntime to call t.Setenv(...) as the first action in the function
(reference newAppsClientRuntime and the call site cmdutil.TestFactory).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cad262b6-f9b7-409c-93ee-75177089ac7c
📒 Files selected for processing (17)
.golangci.ymlinternal/errclass/codemeta_apps.golint/errscontract/rule_no_legacy_common_helper_call.golint/errscontract/rule_no_legacy_envelope_literal.goshortcuts/apps/apps_access_scope_get.goshortcuts/apps/apps_access_scope_set.goshortcuts/apps/apps_create.goshortcuts/apps/apps_create_test.goshortcuts/apps/apps_errors.goshortcuts/apps/apps_html_publish.goshortcuts/apps/apps_html_publish_test.goshortcuts/apps/apps_list.goshortcuts/apps/apps_update.goshortcuts/apps/html_publish_client.goshortcuts/apps/html_publish_client_test.goshortcuts/apps/html_publish_tarball.goshortcuts/apps/walk_html_publish_candidates.go
deb12eb to
8920914
Compare
bf3234d to
166ca41
Compare
166ca41 to
e76456c
Compare
Summary
Apps errors previously left several command-facing paths as legacy
output.Err*/output.Errorfenvelopes or untyped helper errors, so callers had to recover validation, API, and file failures from prose. This PR makes the apps domain's own error producers — flag validation, local HTML publish file handling, SDK/API boundaries, and Miaoda HTML publish business errors — emit typederrs.*errors with stabletype,subtype,param/params,hint,code,log_id, andretryablemetadata where available.What to focus on (reviewer guide)
validation/invalid_argumentplusparam; missingindex.htmlisvalidation/failed_precondition; local pack/read failures carry typed validation or internal/file_io classification.runtime.CallAPITyped; multipart HTML publish keeps rawDoAPIbecause it posts multipart form data, but classifies responses viaruntime.ClassifyAPIResponseand wraps SDK-boundary failures withclient.WrapDoAPIError.90001/90002are scoped to this endpoint, so both their classification (90002→api/not_found) and their recovery hints live in the apps domain instead of the global API code table — the global table stays reserved for service-namespaced codes. Enrichment never overrides a stronger upstream classification and preservescode/log_id.urlnow fails asinternal/invalid_responseinstead of returning an empty url..golangci.ymlandlint/errscontractoptshortcuts/apps/into typed-only, no-bare-wrap, no-legacy-helper, legacy-envelope, and legacy-runtime-helper guards.OutPartialFailureflow.Changes
errs.*builders and apps-local helper functions.runtime.CallAPItoruntime.CallAPITyped.DoAPI, while routing response classification throughruntime.ClassifyAPIResponseand SDK boundary errors throughclient.WrapDoAPIError.90002→api/not_found) and keep their recovery hints local, since these codes are endpoint-scoped rather than service-global; hints are normalized to English.internal/invalid_response.errs.ProblemOfmetadata instead of legacyoutput.ExitErrordetails, and add helper-level tests for path, file I/O, API boundary lifting, endpoint-local code classification, and hint enrichment (including subtype / log_id preservation).LARKSUITE_CLI_CONFIG_DIRso they do not read or write user config state.Test Plan
gofmt -l .git diff --checkgo mod tidyproduced nogo.mod/go.sumdiffgo vet ./...go test ./shortcuts/apps ./internal/errclass ./internal/clientgo test ./errscontractfrom thelintmodulego run -C lint . ..golangci-lint v2.1.6 run --new-from-rev=origin/main— 0 issuesmake unit-testlark-cli apps +create --name Demo --app-type HTML --dry-run --as userlark-cli apps +html-publish --app-id app_x --path <site> --dry-run --as userOutput changes for consumers
type/subtypeplus stable fields such asparam,hint,code,log_id, andretryablewhere the underlying failure provides them.code/log_idand gain command-specific recovery hints; code90002is classifiedapi/not_found.internal/invalid_responseinstead of printing an empty url.Out of scope / deferred
Related Issues
N/A
Summary by CodeRabbit
Improvements
Tests